﻿namespace EFS.RC.ConversationBrowser.Controls
{
	public class Control : System.Windows.Controls.UserControl
	{
		/// Implicit constructor
		public Control()
		{
		}

		/// Property UtilitiesService: Get, Set
		private Proxy.utilitiesSoapClient utilitiesService = null;
		public Proxy.utilitiesSoapClient UtilitiesService
		{
			get
			{
				// first time
				if (null == utilitiesService)
				{
					utilitiesService = EFS.RC.ConversationBrowser.Common.WS.Setup.NewUtilitiesService;
				}

				// ok
				return utilitiesService;
			}
		}

		/// ConstructorNotAllowed
		protected void ConstructorNotAllowed()
		{
			// ignore in design tool
			if (!System.ComponentModel.DesignerProperties.IsInDesignTool)
			{
				throw new System.NotSupportedException("This constructor is not allowed programatically");
			}
		}

		/// Shows an error message
		public void ShowErrorMessage(System.String customError)
		{
			System.Windows.MessageBox.Show(customError, "Error", System.Windows.MessageBoxButton.OK);
		}

		/// Shows an error message
		public void ShowErrorMessage(
			System.String customError,
			System.Exception ex)
		{
			// create builder
			System.Text.StringBuilder sbErr = new System.Text.StringBuilder();
			sbErr.Append(customError);

			// test ex
			if (null != ex && EFS.Common.Verify.String(ex.Message))
			{
				sbErr.AppendFormat("{0}{0}{1}",
					System.Environment.NewLine,
					ex.Message);
			}

			// show
			System.Windows.MessageBox.Show(sbErr.ToString(), "Error", System.Windows.MessageBoxButton.OK);
		}

		/// SleepBetweenRepetitiveAsyncCalls
		public static void SleepBetweenRepetitiveAsyncCalls()
		{
			System.Threading.Thread.Sleep(EFS.RC.ConversationBrowser.Common.Main.MillisecondsBetweenRepetitiveAsyncCalls);
		}
	}

}